<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2024/2/23
 * Time: 16:29
 */

namespace app\api\model;

class GoodsCollect extends Base
{
    /**
     * 多条查询
     * @param $where
     * @param $field
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectData($where = [], $field = '*'){
        return self::where($where)->field($field)->select();
    }

    /**
     * 多条联查
     * @param $where
     * @param $field
     * @param $page
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function selectJoinData($where = [], $field = '*', $page = 1){
        return self::where($where)
            ->join('up_goods', 'collect_goods_id = goods_id', 'LEFT')
            ->field($field)
            ->order('collect_id desc')
            ->page($page, self::$limit)
            ->select();
    }

    /**
     * 单条查询
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findData($where = [], $field = '*'){
        return self::where($where)->field($field)->find();
    }

    /**
     * 删除数据
     * @param $where
     * @return false|int
     */
    static function delData($where = []){
        return self::where($where)->delete();
    }

    /**
     * 统计
     * @param $where
     * @return int|string
     * @throws \think\Exception
     */
    static function countData($where = []){
        return self::where($where)->count();
    }
}